﻿using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Diagnostics;

namespace SomeKit.Serialization
{
    public static partial class SerializationHelper
    {
        public static T ReadObjectFromXmlStream<T>(Stream s)
        {
            var serializer = new DataContractSerializer(typeof(T));
            var res = serializer.ReadObject(s);
            Debug.Assert(res.GetType().IsAssignableFrom(typeof(T)));
            return (T)res;
        }

        public static T ReadObjectFromJsonStream<T>(Stream s)
        {
            var serializer = new DataContractJsonSerializer(typeof(T));
            var res = serializer.ReadObject(s);
            Debug.Assert(res.GetType().IsAssignableFrom(typeof(T)));
            return (T)res;
        }
    }
}
